﻿using System.Collections.Generic;
using System.Linq;
using Microsoft.WowAddonStudio.TocEditor;
using NUnit.Framework;

namespace WowProjectPackage.Tests.TocEditor
{
	[TestFixture]
	public class FileManagerTest
	{
		#region Setup/Teardown

		[SetUp]
		public void SetUp()
		{
			alreadyInFile = new List<string>();
			filesInProject = new List<string>();

			var document = new TocDocument();
			document.Files.Add(frameFile);
			document.Files.Add(soundFile);

			alreadyInFile = document.Files as List<string>;

			filesInProject.Add(frameFile);
			filesInProject.Add(soundFile);
			filesInProject.Add(luaFile);

			manager = new FileListManager(document, filesInProject);
		}

		[TearDown]
		public void TearDown()
		{
		}

		#endregion

		private IFileListManager manager;
		private List<string> alreadyInFile;
		private List<string> filesInProject;

		private const string frameFile = "Frame1.xml";
		private const string soundFile = "Attack.mp3";
		private const string luaFile = "Events.lua";

		[Test]
		public void TestExclude()
		{
			IFileRepresentation first = manager.Files[0];
			Assert.AreEqual(first.IsIncluded, true);
			manager.ChangeIncludeState(first);
			Assert.AreEqual(first.IsIncluded, false);
		}

		[Test]
		public void TestInclude()
		{
			IFileRepresentation last = manager.Files[2];
			Assert.AreEqual(last.IsIncluded, false);
			manager.ChangeIncludeState(last);
			Assert.AreEqual(last.IsIncluded, true);
		}

		[Test]
		public void TestInitialization()
		{
			Assert.IsNotNull(manager.Files);
			Assert.AreEqual(manager.Files.Count, 3);
			Assert.AreEqual(manager.Files.Where(file => file.IsIncluded).Count(), 2);
			Assert.AreEqual(manager.Files.First(file => file.IsIncluded == false).RelativePath, luaFile);
		}

		[Test]
		public void TestMoveDownLast()
		{
			IFileRepresentation last = manager.Files.Last();
			manager.MoveDown(last);

			Assert.AreSame(manager.Files.Last(), last);
		}

		[Test]
		public void TestMoveDownMiddle()
		{
			IFileRepresentation first = manager.Files[0];
			IFileRepresentation middle = manager.Files[1];
			IFileRepresentation last = manager.Files[2];
			manager.MoveDown(middle);

			Assert.AreSame(manager.Files[0], first);
			Assert.AreSame(manager.Files[1], last);
			Assert.AreSame(manager.Files[2], middle);
		}

		[Test]
		public void TestMoveUpFirst()
		{
			IFileRepresentation first = manager.Files.First();
			manager.MoveUp(first);

			Assert.AreSame(manager.Files.First(), first);
		}

		[Test]
		public void TestMoveUpMiddle()
		{
			IFileRepresentation first = manager.Files[0];
			IFileRepresentation middle = manager.Files[1];
			IFileRepresentation last = manager.Files[2];
			manager.MoveUp(middle);

			Assert.AreSame(manager.Files[0], middle);
			Assert.AreSame(manager.Files[1], first);
			Assert.AreSame(manager.Files[2], last);
		}
	}
}